<!DOCTYPE html>
<html>
<head>
	<title>去除空白符</title>
</head>
<body>
<script type="text/javascript">
	
	// 方法一
	let str = ' ab cd ll aj';
	let index;
	do {
		index = str.indexOf(' ', index + 1);
		if(index >= 0) {
			str = str.replace(' ', '')
		}
	} while(index >= 0)
	console.log(str)

 	
	// 方法二
	let stra = '    ab   cd ll aj ';
	let arr = stra.split(' ');
	console.log(arr.join(''))

</script>
</body>
</html>